<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-cn" xml:lang="zh-cn">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="DC.Type" content="topic">
  <meta name="DC.Title" content="步骤1：开启归档模式（仅适用于磐维CMDB）">
  <meta name="product" content="">
  <meta name="DC.Relation" scheme="URI" content="opengauss-0010.html">
  <meta name="prodname" content="">
  <meta name="version" content="">
  <meta name="brand" content="">
  <meta name="DC.Publisher" content="20250306">
  <meta name="prodname" content="csbs">
  <meta name="documenttype" content="usermanual">
  <meta name="DC.Format" content="XHTML">
  <meta name="DC.Identifier" content="postgresql-0010">
  <meta name="DC.Language" content="zh-cn">
  <link rel="stylesheet" type="text/css" href="public_sys-resources/commonltr.css">
  <title>步骤1：开启归档模式（仅适用于磐维CMDB）</title>
 </head>
 <body style="clear:both; padding-left:10px; padding-top:5px; padding-right:5px; padding-bottom:5px">
  <a name="postgresql-0010"></a><a name="postgresql-0010"></a>
  <h1 class="topictitle1">步骤1：开启归档模式（仅适用于磐维CMDB）</h1>
  <div>
   <p>在执行磐维<span style="color:#666666;">CMDB数据库</span>备份前必须开启归档模式，否则将会导致备份失败。</p>
   <div class="section">
    <h4 class="sectiontitle">前提条件</h4>
    <p>主备复制集群要有gs_om工具。</p>
    <p></p>
    <p>操作步骤如下：</p>
   </div>
   <ul>
    <li><strong>单机或主备复制集群：</strong><strong>通过修改配置文件参数开启归档模式，其中</strong><strong>主备复制集群</strong><strong>仅需要在任一节点操作。</strong>
     <ol>
      <li id="postgresql-0010__li26730274197">使用PuTTY，登录磐维CMDB数据库主机。</li>
      <li id="postgresql-0010__li1343189142018">执行以下命令切换至数据库安装用户，以用户名<strong id="postgresql-0010__b0352191712207">omm</strong>为例。<pre class="screen" id="postgresql-0010__screen8767925142014">su - omm</pre></li>
      <li>执行以下命令，创建存放归档日志（WAL日志）的目录和设置目录权限，后续操作以<span class="filepath">“/database/panweidb/archive/”</span>目录为例。<pre class="screen">mkdir -p /database/panweidb/archive/</pre> <pre class="screen">chmod 750 /database/panweidb/archive/</pre></li>
      <li>查询postgresql.conf文件路径，参考以下命令。<pre class="screen">find / -name postgresql.conf 2&gt;&amp;1 |grep -v 'find: '</pre></li>
      <li>执行以下命令，进入postgresql.conf文件，这里以<span class="filepath">“/database/panweidb/data/postgresql.conf”</span>路径为例。<pre class="screen">vi <em>/database/panweidb/data/</em>postgresql.conf</pre></li>
      <li>修改postgresql.conf文件中的wal_level、archive_mode、archive_command、enable_cbm_tracking和panweidb_login_info参数，如下所示：<pre class="screen">wal_level = hot_standby                 # minimal, archive, hot_standby or logical
archive_mode = on               # enables archiving; off, on, or always
archive_command = 'cp %p /database/panweidb/archive/%f'          # command to use to archive a logfile segment
panweidb_login_info = off               #login info
enable_cbm_tracking = on</pre>
       <div class="note">
        <img src="public_sys-resources/note_3.0-zh-cn.png"><span class="notetitle"> </span>
        <div class="notebody">
         <ul>
          <li>将wal_level设置为archive, hot_standby 或 logical三个参数中的任意一个即可。</li>
          <li>将archive_mode设置为on，将panweidb_login_info设置为off，将enable_cbm_tracking设置为on。</li>
          <li>将archive_command设置为 'cp %p /mnt/server/archivedir/%f'。</li>
          <li>修改postgresql.conf文件时，请修改文件中已存在的字段值，请勿在文件中自行新增同样的字段，否则将会影响恢复任务。</li>
         </ul>
        </div>
       </div></li>
      <li>重启数据库。
       <ul>
        <li>若数据库类型为“单机”，执行以下命令。<pre class="screen">pw_ctl restart -D /database/panweidb/data</pre></li>
        <li>若数据库类型为“主备复制”，执行以下2条命令。<pre class="screen">gs_om -t stop</pre> <pre class="screen">gs_om -t start</pre></li>
       </ul>
       <div class="notice" id="postgresql-0010__note171971721125216">
        <span class="noticetitle"><img src="public_sys-resources/notice_3.0-zh-cn.png"> </span>
        <div class="noticebody">
         <p id="postgresql-0010__p201971621175213">数据库重启期间数据库业务会中断，请谨慎操作。</p>
        </div>
       </div></li>
     </ol></li>
    <li><strong>分布式集群：通过ha_ctl工具开启归档模式，</strong><strong>仅需要在目标集群任一节点操作。</strong>
     <ol>
      <li>使用PuTTY，登录磐维CMDB数据库主机。</li>
      <li>执行以下命令切换至数据库安装用户，以用户名<strong id="postgresql-0010__postgresql-0010_b0352191712207">omm</strong>为例。<pre class="screen" id="postgresql-0010__postgresql-0010_screen8767925142014">su - omm</pre></li>
      <li>请参考<a href="opengauss-0009.html">备份前准备</a>获取一组DCS节点IP地址和端口（后续操作均以IP地址为10.0.1.16，端口为2379举例）。</li>
      <li>执行以下3条命令开启归档模式。<pre class="screen">ha_ctl set gtm all -l http://<em>10.0.1.16</em>:<em>2379</em> -p archive_mode=on</pre> <pre class="screen">ha_ctl set coordinator all -l http://<em>10.0.1.16</em>:<em>2379</em> -p archive_mode=on</pre> <pre class="screen">ha_ctl set datanode all -l http://<em>10.0.1.16</em>:<em>2379</em> -p archive_mode=on</pre></li>
      <li>执行以下命令获取集群名称。<pre class="screen">ha_ctl monitor all -l http://<em>10.0.1.16</em>:<em>2379</em></pre> <p>回显中<span class="parmname">“cluster”</span>的值即为集群名称（后续操作均以集群名称为<span class="parmvalue">“panwei”</span>举例）。</p></li>
      <li>执行以下2条命令重启数据库。<pre class="screen">ha_ctl stop all -l http://<em>10.0.1.16</em>:<em>2379</em> -c <em>panwei</em></pre> <pre class="screen">ha_ctl start all -l http://<em>10.0.1.16</em>:<em>2379</em> -c <em>panwei</em></pre>
       <div class="notice">
        <span class="noticetitle"><img src="public_sys-resources/notice_3.0-zh-cn.png"> </span>
        <div class="noticebody">
         <p id="postgresql-0010__postgresql-0010_p201971621175213">数据库重启期间数据库业务会中断，请谨慎操作。</p>
        </div>
       </div></li>
     </ol></li>
   </ul>
  </div>
  <div>
   <div class="familylinks">
    <div class="parentlink">
     <strong>父主题：</strong> <a href="opengauss-0010.html">备份openGauss/磐维CMDB</a>
    </div>
   </div>
  </div>
 </body>
</html>